﻿@using ClassBLL
@using ClassCommon
@using ClassModel
@using System.Text

@{
    ViewBag.Title = "排课任务";
    // Layout = "~/Views/Shared/_ScheduleClass_View.cshtml";
    Layout = null;

    int userid = ViewBag.UserId;
    int pageIndex;
    if (!int.TryParse(this.Request["page"], out pageIndex))
    {
        pageIndex = 0;
    }
    //获取用户任务列表 // 就别翻页了，一下子把所有的任务都提取出来。
    List<t_class_task> list = t_class_task_BLL.List(userid, pageIndex, 6).ToList();
    int taskCount = t_class_task_BLL.GetTaskCountByUserId(userid);

    // 用户是否填写的学校等信息 

    t_class_attachment_info attachInfo = t_class_attachment_info_BLL.GetAttachmentByUserId(userid);


    string addressBuilder = string.Empty;
    if (attachInfo != null)
    {
        attachInfo.Address.
            Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries)
            .ToList()
            .ForEach(address =>
            {
                addressBuilder += string.Format("<span class='select-item'>{0}</span>/", address);
            });

        addressBuilder = addressBuilder.TrimEnd(new char[] { '/' });
    }



    // 当前登录用户信息
    t_classDemo_UserInfo userInfo = ViewBag.user;

    // 翻页的HTML
    string pagingHTML = PagingHelper.getPaingHTML(taskCount, 6, pageIndex);

}


<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link rel="stylesheet" type="text/css" href="/static/newestHTML/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/newestHTML/assets/css/style.css" />
    <link rel="stylesheet" href="/static/newestHTML/assets/css/city-picker.css" />
    <link rel="stylesheet" type="text/css" href="/static/newestHTML/assets/css/main.css" />
    <script src="/static/newestHTML/assets/js/jquery.min.js"></script>
    <script src="/static/newestHTML/js/bootstrap.min.js"></script>
    <script src="/static/newestHTML/assets/js/city-picker.data.js"></script>
    <script src="/static/newestHTML/assets/js/city-picker.js"></script>

    <title>我的排课任务</title>

    <style type="text/css">
        .rfy {
            float: right;
            margin: 0 auto;
            padding-bottom: 20px;
        }

        .fy li a {
            float: left;
            margin-left: 2.5%;
            cursor: pointer;
            height: 30px;
            padding: 0 5px;
            line-height: 30px;
            color: #4D4D4D;
            text-decoration: none;
        }

        .active2 {
            background: #04806F;
            color: #FFFFFF;
        }

        .tipText {
            color: #0FA590;
            font-weight: 400;
        }
    </style>
</head>

<body>
    <!-- 新的头部 -->
    @Html.Partial("___newestHeader")
    <!-- 内容视图 -->
    <div class="con">
        <div class="container" style="padding: 0 50px; background: #FAFAFA; margin-top: 80px; border-left: 8px solid #D5D5D8; border-right: 8px solid #D5D5D8;">

            <div class="row">
                <div class="add">
                    <i></i>
                    <span>新增排课任务</span>
                </div>
            </div>
            <!-- 遍历循环任务 -->
            <div class="row" style="padding-bottom: 30px;">
                <!-- 用户任务div循环 -->
                @for (int l = 0; l < list.Count; l++)
                {
                    <div class="col-lg-4 col-md-6 col-sm-12 ccon">
                        <ul>
                            <li>
                                <div class="ctop">
                                    <img src="/static/newestHTML/assets/css/images/index2-1/icon.png" />
                                    <span>@(list[l].Name.Length > 15 ? list[l].Name.Substring(0, 15) + "..." : list[l].Name)</span>
                                </div>
                                <div class="ctext">
                                    <p>
                                        类型：
									<span>常规</span>
                                    </p>
                                    <p>
                                        状态：
									<span class="ntext">@(list[l].IsCompleted ? "已完成" : "未排课")
                                        <i class="@(list[l].IsCompleted ? "yes" : "no")"></i>
                                    </span>
                                    </p>
                                    <p>
                                        用户：
									<span>@(userInfo.userAccount)</span>
                                    </p>
                                    <p>
                                        创建时间：
									<span style="margin-left: 8px;">@list[l].CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</span>
                                    </p>
                                    <p>
                                        <span class="@(list[l].IsCompleted ? "bj" : "pk")">
                                            <a style="color:white; text-decoration:none;" data-href="OperatorClassDetail?id=@(EncryptHelper.Encrypt(list[l].Id.ToString(), string.Empty))">@(list[l].IsCompleted ? "编辑" : "排课")</a>
                                        </span>
                                        <span class="clickToDelete" data-taskname="@(list[l].Name)" data-taskid="@(list[l].Id)">删除</span>
                                    </p>
                                </div>
                            </li>
                        </ul>
                    </div>
                }
            </div>

            <!-- 翻页的 -->
            @Html.Raw(pagingHTML)
        </div>

        <!-- 添加排课任务的modal -->
        <div class="bg" style="display: none;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-4 col-md-7 col-sm-10 tc">
                        <div class="ttc">
                            <span>添加排课任务</span>
                            <span></span>
                        </div>
                        <div class="col-lg-11 col-md-10 col-sm-10 bc">
                            <div class="bbc">
                                <span>名称</span>
                                <input type="text" name="" id="kcmc" maxlength="15" placeholder="请填写需要添加课程的名称" value="" />
                                <span class="wrapped" style="font-size: 16px; display: inline">还能输入<span class="wordCount" style="font-size:16px;color:#099380">15</span>个字</span>
                                <p style="display: none;">
                                    (
									<span></span>代表必填项 )
                                </p>
                            </div>
                        </div>
                        <div class="col-lg-10 col-md-11 col-sm-12 btc">
                            <ul>
                                <li></li>
                                <li>
                                    <a href="#" title="走班课表怎么排？&#10;联系在线客服~&#10;专业排课师~&#10;3天排出优质课表">走进排课？</a>
                                </li>
                                <li class="cancelTaskLi">
                                    <input type="button" name="" id="qx" value="取消" />
                                </li>
                                <li class="saveTaskLi">
                                    <input type="button" name="" id="bc" value="保存" />
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 当前用户学校的附加信息弹窗 -->
        <div class="bg2" style="display: none;">
            <div class="container">
                <div class="row">
                    <div class="col-lg-4 col-md-7 col-sm-10 tc2">
                        <div class="ttc2">
                            <span>完善信息</span>
                            <span>完善后可免费获得排课秘籍</span>
                            @if (attachInfo != null)
                            { 
                                <span></span>    
                            }
                        </div>
                        <div class="col-lg-11 col-md-10 col-sm-12 information">
                            <p>学校信息</p>
                            <p class="col-lg-12 col-md-12 col-sm-12">
                                学校全称：
								<sup class="icon1"></sup>
                                <input type="text" placeholder="请填写学校全称" id="schoolName" value="@(attachInfo != null ? attachInfo.SchoolName : string.Empty)" />
                                <span>学校全称必填</span>

                            </p>

                            <p class="col-lg-12 col-md-12 col-sm-12">
                                所在地区：
								<sup class="icon1"></sup>
                                <input type="text" id="address" data-toggle="city-picker"  value="@(attachInfo != null ? attachInfo.Address : string.Empty)" placeholder="点击下拉面板中选择省/市/区" data-level="district">
                            </p>
                            <p class="col-lg-12 col-md-12 col-sm-12">
                                学校类型：
								<sup class="icon1"></sup>
                                <select name="" id="schoolType">
                                    <option value="0" @(attachInfo == null ? Html.Raw("selected='seleted'") : Html.Raw(""))>选择学校类型</option>
                                    @if (attachInfo == null)
                                    {
                                        <option value="1">小学</option>
                                        <option value="2">初中</option>
                                        <option value="3">高中</option>
                                        <option value="4">完全中学</option>
                                        <option value="5">大学</option>
                                        <option value="6">培训机构</option>
                                        <option value="7">竞品公司</option>
                                        <option value="8">其他</option>    
                                    }
                                    else
                                    {
                                        <option value="1" @(attachInfo.SchoolType == "1" ? Html.Raw("selected='seleted'") : Html.Raw(""))>小学</option>
                                        <option value="2" @(attachInfo.SchoolType == "2" ? Html.Raw("selected='seleted'") : Html.Raw(""))>初中</option>
                                        <option value="3" @(attachInfo.SchoolType == "3" ? Html.Raw("selected='seleted'") : Html.Raw(""))>高中</option>
                                        <option value="4" @(attachInfo.SchoolType == "4" ? Html.Raw("selected='seleted'") : Html.Raw(""))>完全中学</option>
                                        <option value="5" @(attachInfo.SchoolType == "5" ? Html.Raw("selected='seleted'") : Html.Raw(""))>大学</option>
                                        <option value="6" @(attachInfo.SchoolType == "6" ? Html.Raw("selected='seleted'") : Html.Raw(""))>培训机构</option>
                                        <option value="7" @(attachInfo.SchoolType == "7" ? Html.Raw("selected='seleted'") : Html.Raw(""))>竞品公司</option>
                                        <option value="8" @(attachInfo.SchoolType == "8" ? Html.Raw("selected='seleted'") : Html.Raw(""))>其他</option>    
                                    }

                                </select>
                                <span>学校类型必选</span>
                            </p>

                        </div>
                        <div class="col-lg-11 col-md-10 col-sm-12 oneInformation">
                            <p>个人信息</p>
                            <p class="col-lg-12 col-md-12 col-sm-12">
                                <span class="col-lg-6 col-md-12 col-sm-12 zw">您的职务：
									<sup class="icon1"></sup>
                                    <select name="" id="jobType">
                                        <option value="0" @(attachInfo == null ? Html.Raw("selected='seleted'") : Html.Raw(""))>选择您的职务</option>
                                        @if (attachInfo == null)
                                        { 
                                            <option value="1">教务处负责人</option>
                                            <option value="2">信息负责人</option>
                                            <option value="3">年级主任</option>
                                            <option value="4">教学组长</option>
                                            <option value="5">理科教师</option>
                                            <option value="6">文科教师</option>
                                            <option value="7">教学副校长</option>    
                                        }
                                        else
                                        {
                                            <option value="1" @(attachInfo.Duty == "1" ? Html.Raw("selected='seleted'") : Html.Raw(""))>教务处负责人</option>
                                            <option value="2" @(attachInfo.Duty == "2" ? Html.Raw("selected='seleted'") : Html.Raw(""))>信息负责人</option>
                                            <option value="3" @(attachInfo.Duty == "3" ? Html.Raw("selected='seleted'") : Html.Raw(""))>年级主任</option>
                                            <option value="4" @(attachInfo.Duty == "4" ? Html.Raw("selected='seleted'") : Html.Raw(""))>教学组长</option>
                                            <option value="5" @(attachInfo.Duty == "5" ? Html.Raw("selected='seleted'") : Html.Raw(""))>理科教师</option>
                                            <option value="6" @(attachInfo.Duty == "6" ? Html.Raw("selected='seleted'") : Html.Raw(""))>文科教师</option>
                                            <option value="7" @(attachInfo.Duty == "7" ? Html.Raw("selected='seleted'") : Html.Raw(""))>教学副校长</option>    
                                        }

                                    </select>
                                    <span>职务必选</span>
                                </span>
                                <span class="col-lg-6 col-md-12 col-sm-12 nn">您的年龄：
									<sup class="icon1"></sup>
                                    <select name="" id="ageArrange">
                                        <option value="0" @(attachInfo == null ? Html.Raw("selected='seleted'") : Html.Raw(""))>选择您的年龄</option>
                                        @if (attachInfo == null)
                                        { 
                                            <option value="1">20岁-25岁</option>
                                            <option value="2">25岁-30岁</option>
                                            <option value="3">30岁-35岁</option>
                                            <option value="4">35岁-40岁</option>
                                            <option value="5">40岁-45岁</option>
                                            <option value="6">45岁-50岁</option>
                                            <option value="7">50岁以上</option>
                                        }
                                        else
                                        {
                                            <option value="1" @(attachInfo.AgeRange == "1" ? Html.Raw("selected='seleted'") : Html.Raw(""))>20岁-25岁</option>
                                            <option value="2" @(attachInfo.AgeRange == "2" ? Html.Raw("selected='seleted'") : Html.Raw(""))>25岁-30岁</option>
                                            <option value="3" @(attachInfo.AgeRange == "3" ? Html.Raw("selected='seleted'") : Html.Raw(""))>30岁-35岁</option>
                                            <option value="4" @(attachInfo.AgeRange == "4" ? Html.Raw("selected='seleted'") : Html.Raw(""))>35岁-40岁</option>
                                            <option value="5" @(attachInfo.AgeRange == "5" ? Html.Raw("selected='seleted'") : Html.Raw(""))>40岁-45岁</option>
                                            <option value="6" @(attachInfo.AgeRange == "6" ? Html.Raw("selected='seleted'") : Html.Raw(""))>45岁-50岁</option>
                                            <option value="7" @(attachInfo.AgeRange == "7" ? Html.Raw("selected='seleted'") : Html.Raw(""))>50岁以上</option>
                                        }
                                    </select>
                                    <span>年龄必选</span>
                                </span>
                            </p>
                            <p class="col-lg-12 col-md-12 col-sm-12" style="overflow: hidden; padding-top: 5px;">
                                联系电话：
								<sup class="icon1"></sup>
                                <input type="text" name="" id="phone" value="@(attachInfo != null ? attachInfo.PhoneNum : string.Empty)" placeholder="请填写您的联系电话" />
                                <span>无法联系电话</span>
                            </p>
                            <p class="col-lg-12 col-md-12 col-sm-12">
                                联系QQ：
								<input style="margin-left: 5px;" id="qqNumber" type="text" value="@(attachInfo != null ? attachInfo.QQ : string.Empty)" placeholder="请填写您的QQ" />
                            </p>
                            <p class="col-lg-12 col-md-12 col-sm-12">
                                联系邮箱：
								<input type="text" placeholder="请填写您的邮箱" id="email" value="@(attachInfo != null ? attachInfo.Email : string.Empty)" />
                                <span>无效联系邮箱</span>
                            </p>
                        </div>
                        <p class="col-lg-6 col-md-8 col-sm-10 TJ">
                            <input type="button" id="bc1" value="保存" />
                            @if (attachInfo != null)
                            {
                                <input type="button" id="qx1" value="取消" />    
                            }
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 用户是否设置了 学校等基本信息 -->
    <input type="hidden" id="isAttachment" value="@(attachInfo != null ? "1" : "0")" />

    <!-- 操作弹窗 -->
    <!-- 确定 & 取消 -->
    <div class="popup op_confirm_cancel" style="display: none;">
        <div class="container">
            <div class="row">
                <div class="col-lg-3 col-md-6 col-sm-10 popuptext">
                    <p>操作提示</p>
                    <p class="tip">你正在执行XXX操作，确定要这么做吗？</p>
                    <p>
                        <input type="button" name="" id="confirmPop" value="确定" />
                        <input type="button" name="" id="cancelPop" value="取消" />
                    </p>
                </div>
            </div>
        </div>
    </div>

    <!-- 操作失败 -->
    <div class="popup op_confirm" style="display: none;">
        <div class="container">
            <div class="row">
                <div class="col-lg-3 col-md-6 col-sm-10 popuptext">
                    <p>操作提示</p>
                    <p>你还没有上传课表信息，不能设置节次信息。</p>
                    <p>
                        <input style="width: 100%;" type="button" name="" id="onlyConfirm" value="确定" />
                    </p>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript">
    $(function () {
        // 新建任务弹窗
        $(".add i").click(function () {
            $(".bg").css("display", "block");
        })
        // 关闭任务弹窗
        $(".ttc span:nth-child(2)").click(function () {
            $(".bg").css("display", "none");
        })

        // 字数监控
        $("#kcmc").on("keyup", function () {
            var inputLength = $(this).val().length;
            var maxLength = parseInt($(this).attr("maxlength"));
            var leftLength = maxLength - inputLength;
            if (leftLength == 0) {
                $(".wrapped").hide();
            } else {
                $(".wrapped").show();
            }
            $(".wordCount").text(maxLength - inputLength);
        });

        // 解决取消按钮过小不好点击的问题。
        $(".cancelTaskLi").on("click", function () {
            $(".bg").css("display", "none");
        })

        // 添加任务失去焦点验证操作。
        //$('#kcmc').blur(function () {
        //    //if ($("#kcmc").val() == '') {
        //    //    $(".bbc span:nth-child(3)").addClass('actions1');
        //    //    $(".bbc p").css('display', 'block')
        //    //} else {
        //    //    $(".bbc span:nth-child(3)").removeClass('actions1');
        //    //}
        //})

        $(".ttc1 span:nth-child(3)").click(function () {
            $(".bg1").css("display", "none");
        })

        $('.administrator').click(function () {
            $('.bg2').css('display', 'block');
        })

        $(".ttc2 span:nth-child(3)").click(function () {
            $(".bg2").css("display", "none");
        })

        // 检测用户设置了基本学校信息，来决定是否弹出学校设置框
        var isAttachment = $("#isAttachment").val();
        if (isAttachment == "0") {
            $(".bg2").css("display", "block");
        }

        // 解决排课按钮点击有效区域过小的问题。
        $(".pk,.bj").on("click", function () {
            var $this = $(this);
            var redirectionHref = $this.find("a").eq(0).attr("data-href");
            window.location.href = redirectionHref;
        })

        // 保存排课任务 解决排课保存按钮点击范围过小的问题。
        $(".saveTaskLi").on("click", function () {
            var kcmc = $("#kcmc").val();
            if (!kcmc) {
                $(".bbc span:nth-child(3)").addClass('actions1');
                $(".bbc p").css('display', 'block')
                return;
            } else {
                // 提交新的排课任务
                $(".bbc span:nth-child(3)").removeClass('actions1');
                var requestObj = {
                    url: "/ScheduleClass/AddClassTask",
                    type: "POST",
                    data: {
                        name: kcmc
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data.status) {
                            // alert("数据添加成功!");
                            window.location.reload();
                        } else {
                            showConfirm("[<span class='tipText'>" + kcmc + "</span>] 已经存在!");
                        }
                    }
                };

                $.ajax(requestObj);
            }
        })

        // 取消保存弹窗
        $("#qx1").on("click", function () {
            $(".bg2").css("display", "none");
        })

        // 附加信息保存
        $("#bc1").on("click", function () {
            var result = validateForm();
            if (result) {
                result.operation = (isAttachment == "1" ? "update" : "insert");
                $.ajax({
                    url: "/ScheduleClass/AddAttachment",
                    type: "POST",
                    data: result,
                    dataType: "json",
                    success: function (data) {
                        if (data.status) {
                            // alert("数据添加成功!");
                            window.location.reload();
                        }
                    }
                })
            }
        })

        $(".bg2 input").focus(function () {
            $(this).next().hide();
        })
    })

    // 弹窗相关
    $("#cancelPop").on("click", function () {
        $(".op_confirm_cancel").fadeOut("fast");
    })

    $("#onlyConfirm").on("click", function () {
        $(".op_confirm").css("display", "none");
    })

    $(".clickToDelete").on("click", function () {
        var $this = $(this);
        var taskid = $this.attr("data-taskid");
        $("#confirmPop").attr("data-taskid", taskid);
        $(".tip").html("确定删除 <span class='tipText'>[" + $this.attr("data-taskname") + "]</span> 排课任务吗?");
        $(".op_confirm_cancel").css("display", "block");
    })

    // 确定删除
    $("#confirmPop").on("click", function () {
        var taskId = $(this).attr("data-taskid");
        dxRemoveTask(taskId);
    })

    /// 带确定的提示框
    function showConfirm(message) {
        var $modal = $(".op_confirm");
        $modal.css("display", "block");
        $modal.find("p").eq(1).html(message);
    }

    ///删除排课任务
    function dxRemoveTask(id) {
        var requestObj = {
            url: "/ScheduleClass/RemoveTaskByID",
            type: "GET",
            data: {
                id: id
            },
            dataType: "json",
            success: function (data) {
                if (data.status) {
                    window.location.reload();
                }
            }
        };

        $.ajax(requestObj);
    }




    // 表格验证提交
    function validateForm() {
        //学校全称
        var $schoolType = $('.information p:nth-child(2) input');
        if ($schoolType.val() == '') {
            $('.information p:nth-child(2) span').css('display', 'block');
            return false;
        } else {
            $('.information p:nth-child(2) span').css('display', 'none');
        }


        //学校类型
        var $schoolType = $('.information p:nth-child(4) select');

        if ($schoolType.val() == 0) {
            $('.information p:nth-child(4) span').css('display', 'block');
            return false;
        } else {
            $('.information p:nth-child(4) span').css('display', 'none');
        }


        //您的职务
        var $jobType = $('.oneInformation p:nth-child(2) select');
        if ($jobType.val() == 0) {
            $('.oneInformation p:nth-child(2) span:nth-child(1) span').css('display', 'block');
            return false;
        } else {
            $('.oneInformation p:nth-child(2) span:nth-child(1) span').css('display', 'none');
        }


        //您的年龄
        var $ageArrange = $('.oneInformation p:nth-child(2) span:nth-child(2) select');
        if ($ageArrange.val() == '0') {
            $('.nn span').css('display', 'block');
            return false;
        } else {
            $('.nn span').css('display', 'none');
        }


        //联系电话
        var val = $('.oneInformation p:nth-child(3) input').val();
        var reg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
        if (!reg.test(val)) {
            $('.oneInformation p:nth-child(3) span').css('display', 'block');
            return false;
        } else {
            $('.oneInformation p:nth-child(3) span').css('display', 'none');
        }


        //邮箱验证
        var val = $('.oneInformation p:nth-child(5) input').val();
        var reg = /^(\w-*\.*)+@@(\w-?)+(\.\w{2,})+$/;
        if (!reg.test(val)) {
            $('.oneInformation p:nth-child(5) span').css('display', 'block');
            return false;
        } else {
            $('.oneInformation p:nth-child(5) span').css('display', 'none');
        }

        /*
             schoolName, -- 学校名称
             qqNumber, -- QQ号码
    area, -- 地区
     phone, -- 手机
        schoolType, -- 学校类型id
    jobType, -- 职责类型id

        ageArrange, -- 年龄范围id
        email -- 邮箱
             * */
        return {
            schoolName: $("#schoolName").val(),
            qqNumber: $("#qqNumber").val(),
            area: $("#address").val(),
            phone: $("#phone").val(),
            schoolType: $("#schoolType").val(),
            jobType: $("#jobType").val(),
            ageArrange: $("#ageArrange").val(),
            email: $("#email").val()
        };
    }

</script>

</html>
